﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition.Hosting;
using System.ComponentModel.Composition.Primitives;
using System.Reflection;

namespace AxeFrog.Composition
{
	/// <summary>
	/// A simple fluent interface for building an AggregateCatalog object which is used to
	/// initialize the composition container.
	/// </summary>
	public class CatalogBuilder
	{
		private readonly IList<ComposablePartCatalog> _catalogs = new List<ComposablePartCatalog>();

		public CatalogBuilder ForAssembly(Assembly assembly)
		{
			_catalogs.Add(new AssemblyCatalog(assembly));
			return this;
		}

		public CatalogBuilder ForAssembliesInDirectory(string directory, string pattern)
		{
			_catalogs.Add(new DirectoryCatalog(directory, pattern));
			return this;
		}

		public ComposablePartCatalog Build()
		{
			return new AggregateCatalog(_catalogs);
		}
	}
}